package com.py.korona.db.model;

import android.content.ContentResolver;
import android.content.ContentValues;
import android.database.Cursor;
import android.net.Uri;
import com.py.korona.db.UriBuilder;
import com.py.korona.db.model.base.Entity;
import com.py.korona.db.model.base.EntityDescription;
import com.py.korona.db.model.base.EntityProperty;

public class CategoriesInRoomEntity extends Entity {
    public static String             FieldNameCategory         = "category";
    public static String             FieldNameID               = "_id";
    public static String             FieldNameRoom             = "room";
    public static String             FieldNameComputedCategory = "RoomField1";
    public static String             TableName                 = "categoriesinroom";
    private static EntityDescription entityDescription_;

    public static String ComputedFieldCategories() {
        return String.format("(select group_concat(category.text) from category join categoriesinroom on categoriesinroom.category=category._id where categoriesinroom.room=room._id) as %s", FieldNameComputedCategory);
    }

    public static EntityDescription entityDescription() {
        if (null == entityDescription_) {
            entityDescription_ = new EntityDescription();
            entityDescription_.addProperty(new EntityProperty(CategoriesInRoomEntity.FieldNameID, "integer", null, "primary key autoincrement"));
            entityDescription_.addProperty(new EntityProperty(CategoriesInRoomEntity.FieldNameRoom, "integer", null, "not null"));
            entityDescription_.addProperty(new EntityProperty(CategoriesInRoomEntity.FieldNameCategory, "integer", null, "not null"));
        }
        return entityDescription_;
    }

    public static String entityTableName() {
        return CategoriesInRoomEntity.TableName;
    }

    public static String TableFieldAliasCategory() {
        return String.format("%s.%s", CategoriesInRoomEntity.TableName, CategoriesInRoomEntity.FieldNameCategory);
    }

    public static String TableFieldAliasRoom() {
        return String.format("%s.%s", CategoriesInRoomEntity.TableName, CategoriesInRoomEntity.FieldNameRoom);
    }

    public static String uriAuthority() {
        return "CategoriesInRoomContentProvider";
    }

    public static String uriBasePath() {
        return "categoriesinroom";
    }
    private long category;
    private long room;

    public CategoriesInRoomEntity(ContentResolver contentResolver) {
        super(contentResolver);
    }

    public CategoriesInRoomEntity(ContentResolver contentResolver, Cursor cursor) {
        super(contentResolver, cursor);
    }

    public long getCategory() {
        return category;
    }

    public long getRoom() {
        return room;
    }

    public void setCategory(long category) {
        this.category = category;
    }

    public void setRoom(long room) {
        this.room = room;
    }

    @Override
    protected ContentValues contentValues() {
        ContentValues contentValues = new ContentValues();
        contentValues.put(CategoriesInRoomEntity.FieldNameRoom, this.getRoom());
        contentValues.put(CategoriesInRoomEntity.FieldNameCategory, this.getCategory());
        return contentValues;
    }

    @Override
    protected Uri objectsListUri() {
        return UriBuilder.objectListUri(CategoriesInRoomEntity.uriAuthority(), CategoriesInRoomEntity.uriBasePath());
    }

    @Override
    protected void onDataChanged(Cursor cursor) {
        // TODO Auto-generated method stub
    }
}
